<DOCTYPE html>
<!--HTML5 doctype-->
<html>
<head>
	<title>护理文书</title>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<link rel="stylesheet" type="text/css" href="../../css/jquery.mobile-1.4.0.css" />
	<link rel="stylesheet" type="text/css" href="../../css/zpdydhl_mobile.css">
	<link rel="stylesheet" type="text/css" href="../../css/mobiscroll.custom-2.6.2.min.css">
	<script type="text/javascript" src="../../js/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.mobile-1.4.0.min.js"></script>
	<script type="text/javascript" src="../../js/zpdydhl_mobile.js"></script>
	<script type="text/javascript" src="../../js/mobiscroll.custom-2.6.2.min.js"></script>
	<style type="text/css">
	.replaceable_tips { 
		padding:5px; 
		width:auton; 
		/*max-height:150px;*/ 
		position:absolute; 
		z-index:100; 
		background-color:#EAEAEA; 
		border:1px solid 
		blue;
	}
	.replaceable_tips li {
		cursor:pointer; 
		list-style:none; 
		width:100%; 
		line-height:25px; 
		font-size:20px; 
		text-align:left;
		margin-top: 5px;
	}
	.replaceable_tips li:hover {background-color:#6A6A6A}
	.error_state { color:#F00;cursor:pointer;}
	.right_state { color:#063;cursor:pointer;}
	.replace_state { color:#063;cursor:pointer;}

	.hulijilu_table{ width:100%; margin-bottom:10px;}
	.hulijilu_table tr td{border:1px solid #c5dbf2;height:36px;}
	.content_edit{border:1px dashed #1e8cc3;display:block;min-height:30px;line-height:30px;word-break: break-all;word-wrap: break-word;}
	.hulijilu_table_title{color:#027fbd;text-align:right;width:100px;}
	ul.huli_list{list-style-type:none;padding:0;margin:0; border-bottom:1px solid #ccc; clear:both;padding-bottom:5px;margin-bottom:10px;overflow:hidden;}
	ul.huli_list li{margin-left:10px;line-height:22px;}
	ul.huli_list li span{color:#027fbd;}
	</style>
</head>
<body>
	<div data-role="page" data-theme="c" id="page">
	 	
		<div class="content" style="padding:8px;" contenteditable="false">
			
				
			
		</div>
		<input type="hidden" name="id" value="">
		<input type="hidden" name="list" value="">
		<script type='text/javascript'>
			var col_title;
			$(function () {
				huliwenshu_id=getRequestOne("huliwenshu_id");
				huli_wenshu_type = decodeURI(getRequestOne("type"));
				
			})
			function refreshData()
			{
				$.ajax({
					type: "get",
					async: false,
					url:server_url+"Mobile/HuliWenshu/showDetailHuliWenshuJson"+yiyuan_id,
					data: { id : huliwenshu_id,zhuyuan_id:patient_info_global.zhuyuan_id,user_number:nurse_info_global.user_number},
					dataType: "jsonp",
					jsonp: "callbackShowDetailHuliWenshuJson",
					jsonpCallback:"feedBackStateShowDetailHuliWenshuJson",
					error:function(mes)
					{
						alert(mes);
					},
					success: function(result) {
						
						if(result.ret=="success")
						{
							if(result.list=="false")
							{
								$("#save").css("display","block");
								var str = '<table border="0" cellpadding="0" cellspacing="0" class="hulijilu_table">';
								col_title='{';
								for (var i=0;i<result.data.length;i++)
								{
									str +='<tr><td width="150px" class="hulijilu_table_title">'+result.data[i]+':</td><td><div contenteditable="true" class="content_edit" name="col'+eval(i+1)+'"></div></td></tr>';
									col_title+='"col'+eval(i+1)+'"'+':"'+result.data[i]+'",';
								}
								col_title = col_title.substr(0,col_title.length-1)
								col_title+='}';
								col_title = JSON.parse(col_title);
								str +='</table>';
								$('.content').html(str);
								
							}
							else if(result.list=="true")
							{
								$("#add").css("display","block");
								var str = '';
								for (var i=1;i<result.data.length;i++)
								{	
									str += '<ul class="huli_list" sub_id="'+result.data[i].id+'">';
									str += '<li><span>护理时间:</span>'+result.data[i].record_time;
									str += '</li>';
									str += '<li><span>操作者:</span>'+result.data[i].record_user_name;
									str += '</li>';
									for (var j=0;j<result.data_title.length;j++)
									{
										str += '<li><span>'+result.data_title[j]+':</span>'+result.data[i]['col'+(j+1)]+'</li>';
									}
									str += '</ul>';
									
								}
								
									
								$('.content').html(str);
							}
							else if(result.list=="one")
							{
								$("#save").css("display","block");
								//$('.content').attr("contenteditable","true");
								$('.content').html(result.data.mobile_content);
							}
							$("[name='id']").val(result.id)
							$("[name='list']").val(result.list)
						}
						else
							alert("失败");
					}
				});
				$(".ui-page").show();
			}
			$(".prev").die().live("click",function(){
				window.location.href="./showHuliwenshu.html?type="+huli_wenshu_type
			});
			$("#add").die().live("click",function(){
				window.location.href="./addHuliwenshu.html?huliwenshu_id="+$("[name='id']").val()+"&type="+huli_wenshu_type;
			});
			$("#save").die().live("click",function(){
				if ($("[name='list']").val()!='one')
				{
					var col_data='{';
					$(".content_edit").each(function(){
						col_data+='"'+$(this).attr('name')+'"'+':"'+$(this).text()+'",';
					})
					col_data = col_data.substr(0,col_data.length-1)
					col_data+='}';
					col_data = JSON.parse(col_data)
				}
				
				//console.log(col_data);
				url=server_url+"Mobile/HuliWenshu/updateHuliWenshu"+yiyuan_id;
				$.post(url,{id:$("[name='id']").val(),list:$("[name='list']").val(),col_data:col_data,col_title:col_title,content:$('.content').html(),user_number:nurse_info_global.user_number},function(data){
					alert(data);
					window.location.href="./editHuliwenshu.html?huliwenshu_id="+$("[name='id']").val()+"&type="+huli_wenshu_type;
				})
			});
			$(".huli_list").die().live("click",function(){
				window.location.href="./editHuliwenshuSubContent.html?huliwenshu_id="+$("[name='id']").val()+"&sub_id="+$(this).attr("sub_id")+"&type="+huli_wenshu_type;
			})
			$('.content').live("mouseup",function(e){
				// 清空所有[onEdditing='true'](避免点击一个标签改变多处的问题)
				$(".content").each(function(){
					$(this).attr("onEdditing","false");
				});
				if(event.target.nodeName=="TIANTANEE")
				{
					// var keyword = $(event.target).attr("keyword");
					var offset = $(event.target).offset();
					var x_position = offset.left;
					var y_position = offset.top;
					
					$(event.target).attr("onEdditing","true");
					
					var data = "";
					if($(event.target).attr("element_type")=="select" || $(event.target).attr("element_type")=="选择输入")
					{
						var replace_array = $(event.target).attr("replace_list").split("#|");
						for (var i = 0; i < replace_array.length; i++)
						{
							if(replace_array[i].indexOf("(\\d*)")!=-1)
							{
								data+="<li type='number'>"+replace_array[i].replace(/\(\\d\*\)/g,"<input class='replaceable_tips_number' style='width:30px'/>")+"</li>";
							}
							else
							{
								data+="<li type='normal'>"+replace_array[i]+"</li>";
							}
						}
					}
					if($(event.target).attr("element_type")=="number" || $(event.target).attr("element_type")=="数值输入")
					{
						data+="<li type='number' style='width:200px'><input class='replaceable_tips_number' style='width:100px'/></li>";
					}
						
					data+="<li type='delete'><img id='replaceable_tips_delete' src='/zpdydhl/Public/css/images/btn_del.png' />删除</li>";

					var replaceable_div = "<div class='replaceable_tips'>"+data+"</div>";
					$.post("/zpdydhl/TextProcessingEngine/test",function(){
						$("body").append(replaceable_div);
						$(".replaceable_tips").offset({top:y_position+20,left:x_position});
					});
			
					// 替换
					$(".replaceable_tips li").live("click",function(){
						if($(this).attr("type")=="number")
						{
							// 带有数字输入框的li
							if($(event.target).is("input"))
							{
								// 如果点击的是输入框直接返回
								return;
							}
							else
							{
								// 如果点击li中非input部分执行以下代码
								$(".replaceable_tips_number").each(function(index,domEle){
									console.log(domEle);
									$(domEle).replaceWith($(domEle).val());
								});
								$("[onEdditing='true']").text($(this).html());
								$("[onEdditing='true']").attr("onEdditing","false");
								
							}					
						}
						else if($(this).attr("type")=="normal")
						{
							// 普通li
							$("[onEdditing='true']").text($(this).text());
							$("[onEdditing='true']").attr("onEdditing","false");
						}
						else if($(this).attr("type")=="delete")
						{
							// 带有删除按钮的li
							$("[onEdditing='true']").remove();
							if(window.document.getElementById("element_info"))
							{
								element_info.window.analyseElement();
							}
						}
						$(".replaceable_tips").remove();
					});
					
					//$(this).blur();
				}
				if($(".replaceable_tips").is(":hidden")==false)
				{
					$(".replaceable_tips").remove();
				}
			});
		</script>
	</div>
</body>
</html>